package com.gitee.huanminabc.fastboot.load.stage.prestage;

import com.gitee.huanminabc.fastboot.context.AppContext;
import com.gitee.huanminabc.fastboot.proxy.ByteBuddyProxy;
import com.gitee.huanminabc.fastboot.proxy.InterceptorHandle;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: ByteBuddy 预加载优化
 * @author: huanmin
 * @create: 2025-04-08 17:34
 **/
@Slf4j
public class BytebuddyPreload implements AppLoadPreStage {
    public void test() {}
    public  void run() {
        if (!AppContext.appBaseInfoConfig.getAop()) {
            return;
        }
        try {
            Class<BytebuddyPreload> defaultClass = BytebuddyPreload.class;
            Method test = defaultClass.getDeclaredMethod("test");
            Map<Method, InterceptorHandle> handleMap = new HashMap<>();
            handleMap.put(test, new InterceptorHandle() {
            });
            ByteBuddyProxy.createProxy(defaultClass, handleMap);
        } catch (NoSuchMethodException e) {
            log.error("BytebuddyPreload 预加载失败:",e);
            System.exit(1);
        }
    }
}
